package com.dc.trans.steps.decryptvalidatesign;

import java.util.List;
import java.util.Map;

import org.pentaho.di.core.CheckResultInterface;
import org.pentaho.di.core.Counter;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.w3c.dom.Node;

public class DecryptValidateSignMeta extends BaseStepMeta implements StepMetaInterface{

	private static Class<?> PKG = DecryptValidateSignMeta.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$
	private String stepName;
	private boolean isDecrypt;
	private boolean isValidateSign;
	
	
	public DecryptValidateSignMeta() {
		super();
	}

	public String getStepName() {
		return stepName;
	}

	public void setStepName(String stepName) {
		this.stepName = stepName;
	}
	


	public boolean isDecrypt() {
		return isDecrypt;
	}

	public void setDecrypt(boolean isDecrypt) {
		this.isDecrypt = isDecrypt;
	}

	public boolean isValidateSign() {
		return isValidateSign;
	}

	public void setValidateSign(boolean isValidateSign) {
		this.isValidateSign = isValidateSign;
	}

	@Override
	public void check(List<CheckResultInterface> remarks, TransMeta transMeta,
			StepMeta stepMeta, RowMetaInterface prev, String[] input,
			String[] output, RowMetaInterface info) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public StepInterface getStep(StepMeta stepMeta,
			StepDataInterface stepDataInterface, int copyNr,
			TransMeta transMeta, Trans trans) {
		// TODO Auto-generated method stub
		return new DecryptValidateSign(stepMeta, stepDataInterface, copyNr, transMeta, trans);
	}

	@Override
	public StepDataInterface getStepData() {
		return new DecryptValidateSignData();
	}

	@Override
	public void loadXML(Node stepnode, List<DatabaseMeta> databases,
			Map<String, Counter> counters) throws KettleXMLException {
		// TODO Auto-generated method stub
		readData(stepnode, databases);
	}

	private void readData(Node stepnode, List<DatabaseMeta> databases) throws KettleXMLException {
		try
		{
			stepName       = XMLHandler.getTagValue(stepnode, "stepName"); //$NON-NLS-1$
			isDecrypt        = "Y".equalsIgnoreCase( XMLHandler.getTagValue(stepnode, "isDecrypt") );
			isValidateSign   = "Y".equalsIgnoreCase( XMLHandler.getTagValue(stepnode, "isValidateSign") );
		}
		catch(Exception e)
		{
			throw new KettleXMLException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnableToReadStepInfoFromXML"), e); //$NON-NLS-1$
		}
		
	}

	@Override
	public void readRep(Repository rep, ObjectId id_step,
			List<DatabaseMeta> databases, Map<String, Counter> counters)
			throws KettleException {
		try
		{
			stepName     = rep.getStepAttributeString(id_step, "stepName"); //$NON-NLS-1$
			isDecrypt        = rep.getStepAttributeBoolean(id_step, "isDecrypt");
			isValidateSign   = rep.getStepAttributeBoolean(id_step, "isValidateSign");
		}
		catch(Exception e)
		{
			throw new KettleException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnexpectedErrorReadingStepInfoFromRepository"), e); //$NON-NLS-1$
		}
		
	}

	@Override
	public void saveRep(Repository rep, ObjectId id_transformation,
			ObjectId id_step) throws KettleException {
		try
		{
			rep.saveStepAttribute(id_transformation, id_step, "stepName",stepName); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "isDecrypt",isDecrypt);
			rep.saveStepAttribute(id_transformation, id_step, "isValidateSign",isValidateSign);
		}
		catch(Exception e)
		{
			throw new KettleException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnableToSaveStepInfoToRepository")+id_step, e); //$NON-NLS-1$
		}
		
	}

	@Override
	public void setDefault() {
		// TODO Auto-generated method stub
		
	}
	public String getXML()
	{
        StringBuilder retval = new StringBuilder(400);
		retval.append("    ").append(XMLHandler.addTagValue("stepName", stepName));
		retval.append("    ").append(XMLHandler.addTagValue("isDecrypt", isDecrypt));
		retval.append("    ").append(XMLHandler.addTagValue("isValidateSign", isValidateSign));
		return retval.toString();
	}

}
